﻿namespace MatrixRotatingWalkTest
{
    using System;
    using MatrixRotatingWalk;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class MatrixTest
    {
        [TestMethod]
        public void GeneratedMatrixWithSize1IsCorrect()
        {
            Matrix matrix = new Matrix(1);
            matrix.GenerateMatrix();

            int[,] resultMatrix = matrix.IntMatrix;
            int[,] expectedMatrix = { { 1 } };
            CollectionAssert.AreEqual(resultMatrix, expectedMatrix);
        }

        [TestMethod]
        public void GeneratedMatrixWithSize3IsCorrect()
        {
            Matrix matrix = new Matrix(3);
            matrix.GenerateMatrix();

            int[,] resultMatrix = matrix.IntMatrix;
            int[,] expectedMatrix = {
                                    {1, 7, 8},
                                    {6, 2, 9},
                                    {5, 4, 3}
                                    };
            CollectionAssert.AreEqual(resultMatrix, expectedMatrix);
        }

        [TestMethod]
        public void GeneratedMatrixWithSize6IsCorrect()
        {
            Matrix matrix = new Matrix(6);
            matrix.GenerateMatrix();

            int[,] resultMatrix = matrix.IntMatrix;
            int[,] expectedMatrix = {
                                    {1, 16, 17, 18, 19, 20},
                                    {15, 2, 27, 28, 29, 21},
                                    {14, 31, 3, 26, 30, 22},
                                    {13, 36, 32, 4, 25, 23},
                                    {12, 35, 34, 33, 5, 24},
                                    {11, 10, 9, 8, 7, 6}
                                    };
            CollectionAssert.AreEqual(resultMatrix, expectedMatrix);
        }

        [TestMethod]
        public void PrintMethodOnMatrixWithSize4WorksCorect()
        {
            Matrix matrix = new Matrix(4);
            matrix.GenerateMatrix();

            string resultString = matrix.ToString();
            string expectedSring =
                "   1  10  11  12\r\n" +
                "   9   2  15  13\r\n" +
                "   8  16   3  14\r\n" +
                "   7   6   5   4\r\n";
            Assert.AreEqual(resultString, expectedSring);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void GeneratedMatrixWithNegativeSizeThrowException()
        {
            Matrix matrix = new Matrix(-1);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void GeneratedMatrixWithOverMaximumSizeThrowException()
        {
            Matrix matrix = new Matrix(101);
        }
    }
}
